package com.yanqu.road.server.timer.estatewar;

import com.yanqu.road.entity.player.PlayerState;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.EstateWarModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.LocalDateTimeHelper;
import com.yanqu.road.utils.executor.GeneralTask;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class EstateWarCheckDailyRewardTask extends GeneralTask {

	private Logger logger = LogManager.getLogger(this.getClass().getName());

	private long lastCheckTime;

	private boolean isRun = false;

	@Override
	public void doRun() {
		long zeroTime = LocalDateTimeHelper.getZeroTimeTimeStamp();
		if(lastCheckTime < zeroTime && !isRun){
			isRun = true;
			try {
				for (GamePlayer player : GamePlayerMgr.getCopyPlayerMap().values()) {
					if(player.getState()== PlayerState.ONLINE){//乔迁风云每日奖励
						player.getModule(EstateWarModule.class).checkDailyReward();
					}
				}
				lastCheckTime = zeroTime;
			}catch (Exception e){
				logger.error("estate war check daily reward error:", e);
			}finally {
				isRun = false;
			}
		}
	}
}
